home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 7_3.lha / 7_3 / 7_3a.c next >
Text File  |  1993-08-08  |  1KB  |  102 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / exercise 7.3
  6. lass triangle: public shape
  7.  
  8.    point sw, se, top;
  9.  
  10.    int UP()
  11.    {
  12. return (top.y >= se.y) ?
  13.     ( (top.y >= sw.y) ? top.y : sw.y ) :
  14.     (se.y >= sw.y) ? se.y : sw.y;
  15.    }
  16.  
  17.    int RIGHT()
  18.    {
  19. return (top.x >= se.x) ?
  20.     ( (top.x >= sw.x) ? top.x : sw.x ) :
  21.     (se.x >= sw.x) ? se.x : sw.x;
  22.    }
  23.  
  24.    int DOWN()
  25.    {
  26. return (top.y <= se.y) ?
  27.     ( (top.y <= sw.y) ? top.y : sw.y ) :
  28.     (se.y <= sw.y) ? se.y : sw.y;
  29.    }
  30.  
  31.    int LEFT()
  32.    {
  33. return (top.x <= se.x) ?
  34.     ( (top.x <= sw.x) ? top.x : sw.x ) :
  35.     (se.x <= sw.x) ? se.x : sw.x;
  36.    }
  37.  
  38.  
  39. ublic:
  40.    triangle(point a, point b, point c)
  41.    {
  42. sw = a; top = b; se = c;
  43.    }
  44.  
  45.    void move(int x, int y)
  46.    {
  47. sw.x += x;
  48. sw.y += y;
  49. top.x += x;
  50. top.y += y;
  51. se.x += x;
  52. se.y += y;
  53.    }
  54.  
  55.    void draw()
  56.    {
  57. put_line(sw, top);
  58. put_line(top, se);
  59. put_line(se, sw);
  60.    }
  61.  
  62.    point north()
  63.    {
  64. return point((LEFT() + RIGHT()) / 2, UP());
  65.    }
  66.  
  67.    point south()
  68.    {
  69. return point((LEFT() + RIGHT()) / 2, DOWN());
  70.    }
  71.  
  72.    point east()
  73.    {
  74. return point(LEFT(), (UP() + DOWN()) / 2);
  75.    }
  76.  
  77.    point west()
  78.    {
  79. return point(RIGHT(), (UP() + DOWN()) / 2);
  80.    }
  81.  
  82.    point swest()
  83.    {
  84. return point(LEFT(), DOWN());
  85.    }
  86.  
  87.    point seast()
  88.    {
  89. return point(RIGHT(), DOWN());
  90.    }
  91.  
  92.    point nwest()
  93.    {
  94. return point(LEFT(), UP());
  95.    }
  96.  
  97.    point neast()
  98.    {
  99. return point(RIGHT(), UP());
  100.    }
  101. ;
  102.